<?php
#####################################################
# RWCARDS - Mambo E-Cards verschicken!
# Copyright (C) 2004/2005 by Ralf Weber
# Company    : Superwebba
# Homepage   : www.weberr.de
# Version    : 1.2.2
# Date       : 21/03/2005
# License    : Released under GPL
######################################################


defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

require_once( $mainframe->getPath( 'admin_html' ) );

// Pager
require_once($GLOBALS['mosConfig_live_site'] . '/components/com_rwcards/Pager/Pager.php');

class rwcards_categories
{

function RWCardsGetCategories($option)
{
  global $mainframe, $database;

  $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', 10 );
  $limitstart = $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 );
  $search = $mainframe->getUserStateFromRequest( "search{$option}", 'search', '' );
  $search = $database->getEscaped( trim( strtolower( $search ) ) );
  $where = $search ? " WHERE rwcards_category_kategorien_name LIKE '%" . $search . "%'" : "";

  // get the total number of records
  $database->setQuery( "SELECT COUNT(*) FROM #__rwcards_category $where" );
  $total = $database->loadResult();

  require_once( "includes/pageNavigation.php" );
  $pageNav = new mosPageNav( $total, $limitstart, $limit  );

  $q_raw = "SELECT p.*, u.name AS editor"
    . "\nFROM #__rwcards_category AS p"
    . "\nLEFT JOIN #__users AS u ON u.id = p.rwcards_checked_out"
    . "\n" . $where
    . "\nORDER BY rwcards_ordering, rwcards_category_kategorien_name ASC"
    . "\nLIMIT $pageNav->limitstart, $pageNav->limit";
  $database->setQuery( $q_raw );
  $rows = $database->loadObjectList();

  echo '<p class="error">' . $database->getErrorMsg() . '</p>';

  rwcards_html::setRWCardsListCategories( $rows, $pageNav, $search, $option );
	/*
	$database->setQuery("SELECT * FROM #__rwcards_category");
	$daten = $database->loadObjectList();
	rwcards_html::setRWCardsMainscreen();
	rwcards_html::setRWCardsListCategories($daten);
	rwcards_html::setRWCardsFooter();
	*/
}

function listReference( $option ) {
  global $mainframe, $database;

  $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', 10 );
  $limitstart = $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 );
  $search = $mainframe->getUserStateFromRequest( "search{$option}", 'search', '' );
  $search = $database->getEscaped( trim( strtolower( $search ) ) );
  $where = $search ? " WHERE p.name LIKE '%" . $search . "%' OR p.description LIKE '%" . $search . "%'" : "";

  // get the total number of records
  $database->setQuery( "SELECT COUNT(*) FROM #__referencelist $where" );
  $total = $database->loadResult();

  require_once( "includes/pageNavigation.php" );
  $pageNav = new mosPageNav( $total, $limitstart, $limit  );

  $q_raw = "SELECT p.*, u.name AS editor"
    . "\nFROM #__referencelist AS p"
    . "\nLEFT JOIN #__users AS u ON u.id = p.checked_out"
    . "\n" . $where
    . "\nORDER BY ordering, name ASC"
    . "\nLIMIT $pageNav->limitstart, $pageNav->limit";
  $database->setQuery( $q_raw );
  $rows = $database->loadObjectList();

  echo '<p class="error">' . $database->getErrorMsg() . '</p>';

  HTML_referencelist::displayList( $rows, $pageNav, $search, $option );
}

}//end class
?>